<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">

    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <script src="./js/jquery.js" type="text/javascript"></script>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">医院管理</a>
                <a>
                    <cite>医院停用列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="AddressId" lay-filter="AddressId" id="AddressId" lay-search="" lay-verify="select">
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" id="hospitalName" placeholder="请输入医院名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline layui-show-xs-block" >
                            <input type="button" data-type="reload" class="layui-icon layui-btn"  id="select" value=&#xe615 />
                        </div>
                    </form>
                </div>

                <div class="layui-card-body ">
                    <table  cellpadding="0" cellspacing="0" class="layui-table"  id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

</body>
<script>
    $(function(){
        $.ajax({
            type:"get",
            url:"/hospital/homePage/select",
            dataType:"json",
            async: false,
            success:function(data){
                console.log(data);
                var AddressId=data.data;
                $("#AddressId").append("<option value=0>--请选择--</option>")
                for(var i=0;i<data.data.length;i++){
                    var j=90+AddressId[i].addressId;
                    $("#AddressId").append("<option value="+j+">"+AddressId[i].areaName+"</option>")
                }
            }
        })
    })

    layui.use('table', function(){
        var form=layui.form;
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'/hospital/api/back/hospitala/stop/limit'
            ,cellMinWidth:80
            ,parseData: function(res){ //res 即为原始返回的数据
                console.log(res)
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.page1.total ,//解析数据长度
                    "data": res.data.userList//解析数据列表
                };
            }
            ,response: {
                statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,page: true //开启分页
            ,limit:5
            ,limits: [5, 10, 15,20] //自定义分页数据选项
            ,cols: [[
                {field:'hospitalId', width:'5%', title:'ID', sort: true}
                ,{field:'hospitalName', width:'15%', title: '医院名称'}
                ,{field:'hospitalphone', width:'20%', title: '座机号码'}
                ,{field:'gradeName', width:'15%', title: '医院类型'}
                ,{field:'typeName', title:'医院等级',width:'15%' }
                ,{field:'areaName', width:'10%', title: '地区'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:'20%'}
            ]]
            ,id: 'testReload'
            ,page: true
        }); var $ = layui.$, active = {
            reload: function(){
                var AddressId=$("#AddressId").val();

                var hospitalName=$("#hospitalName").val();

                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        AddressId: AddressId,
                        hospitalName:hospitalName,
                    }
                }, 'data');
            }
        };
        $('#select').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'blacklist'){
                layer.confirm('确定要启用吗？', function(index){

                    $.ajax({
                        type:"get",
                        url:"/hospital/api/back/hospitala/black",
                        data:{"hospitalId":data.hospitalId,"AddressId":data.addressId},
                        dataType:"json",
                        success:function(data){
                            console.log(data);
                            layer.msg("启用成功", {
                                icon: 1
                            });
                            table.reload('testReload', {
                                page: {
                                    curr: 1 //重新从第 1 页开始
                                }
                            }, 'data');
                        }
                    });
                    layer.close(index);
                })
            }
        });
    })
</script>
<script type="text/html" id="barDemo">
    <a title="查看" class="layui-btn layui-btn-xs" lay-event="see"onclick="xadmin.open('查看','3hospital-view.html?id='+'{{d.hospitalId}}')" href="javascript:;">
        <i class="layui-icon">&#xe615;</i>
    </a>
    <a title="启用" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="blacklist"><i class="layui-icon">&#xe6af;</i></a>
</script>



</html>
